/**
 * Een Inode object representeert een actieve inode.
 * [Denk aan de AIT].
 */

#include "utility/ino.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include "utility/const.h"
#include <vector>
#include <time.h>
using namespace std;

#ifndef INODE_H_
#define INODE_H_

class Inode {
private:
	void readfirstBlocks(int blockp, byte * b);
	void readsecondBlocks(int blockp, byte * b);
	void readthirdBlocks(int blockp, byte * b);

	bool isFull() {
		return (blocks.size() * DBLKSIZ) < di_size;
	}

	void addBlock(int b) {
		if (b == 0)
			return;
		blocks.push_back(b);
	}

public:
	int inode_nr;
	imode_t di_mode; /* mode and type of file (see below) */
	short di_nlink; /* number of links to file */
	id_x di_uid; /* owner's user id */
	id_x di_gid; /* inode's group id */
	off_x di_size; /* number of bytes in file */
	int di_addr[13]; /* disk block addresses (see below) */
	vector<int> blocks; /* file data blocks */
	time_t di_atime; /* time last accessed */
	time_t di_mtime; /* time last modified */
	time_t di_ctime; /* time created/changed */

	void print();
	void dumpToFile(byte * b);

	bool isDir();
	bool isFIFO();
	bool isCharSpecial();
	bool isCharMultiplex();
	bool isBlockSpecial();
	bool isBlockMultiplex();
	bool isRegular();

	dinode inodeInfo;
	Inode(byte * d, int pos, int num);
	virtual ~Inode();
};

#endif /* INODE_H_ */
